package com.scvtc.controller.student;

import com.scvtc.domain.ResResult;
import com.scvtc.domain.dto.student.award.StudentAwardDto;
import com.scvtc.domain.vo.PageVo;
import com.scvtc.domain.vo.student.award.StudentAwardVo;
import com.scvtc.service.student.StudentAwardsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Digits;
import java.util.List;

import static com.scvtc.constants.SystemCheckedConstants.PAGE_CURRENT_ERROR;
import static com.scvtc.constants.SystemCheckedConstants.PAGE_SIZE_ERROR;
import static com.scvtc.constants.SystemConstants.PAGE_CURRENT;
import static com.scvtc.constants.SystemConstants.PAGE_SIZE;

/**
 * 学生获奖信息(StudentAwards)表控制层
 *
 * @author yiFei
 * @since 2022-04-13 17:38:27
 */
@Api(tags = "学生获奖信息(StudentAwards)")
@RestController
@RequestMapping("studentAwards")
public class StudentAwardsController {
    /**
     * 学生获奖信息(StudentAwards)对象
     */
    @Autowired
    private StudentAwardsService studentAwardsService;

    @GetMapping("/list")
    @ApiOperation("查询学生获奖信息")
    @PreAuthorize("hasAuthority('student:award:list')")
    public ResResult<PageVo<List<StudentAwardVo>>> getAllStudentBase(
            @Digits(integer = 5, fraction = 1, message = PAGE_CURRENT_ERROR) @RequestParam(defaultValue = PAGE_CURRENT) Long current,
            @Digits(integer = 3, fraction = 0, message = PAGE_SIZE_ERROR) @RequestParam(defaultValue = PAGE_SIZE) Long size,
            StudentAwardVo studentAwardVo
    ) {
        return studentAwardsService.getAllStudentAwards(current, size, studentAwardVo);
    }

    @PostMapping("/")
    @ApiOperation("添加单个奖状")
    @PreAuthorize("hasAuthority('student:award:add')")
    public ResResult<?> addStudentBase(@RequestBody StudentAwardDto studentAwardDto) {
        return studentAwardsService.addStudentAwards(studentAwardDto);
    }

    @PutMapping("/")
    @ApiOperation("修改单个奖状")
    @PreAuthorize("hasAuthority('student:award:update')")
    public ResResult<?> updateStudentBase(@RequestBody StudentAwardDto studentAwardDto) {
        return studentAwardsService.updateStudentAwards(studentAwardDto);
    }

    @DeleteMapping("/")
    @ApiOperation("删除单个奖状")
    @PreAuthorize("hasAuthority('student:award:delete')")
    public ResResult<?> deleteStudentBase(Long id) {
        return studentAwardsService.deleteStudentAwards(id);
    }

    @DeleteMapping("/multiple")
    @ApiOperation("删除多个奖状")
    @PreAuthorize("hasAuthority('student:award:delete')")
    public ResResult<?> deleteMultipleStudentBase(Long[] ids) {
        return studentAwardsService.deleteMultipleStudentAwards(ids);
    }


}

